# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lz4
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.8.2
pkgrel=1
pkgdesc="Very fast lossless compression algorithm (mingw-w64)"
arch=('any')
url="http://www.lz4.org/"
license=('BSD' 'GPL2')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
checkdepends=('diffutils')
options=('staticlibs' 'strip')
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/lz4/lz4/archive/v${pkgver}.tar.gz"
        "001-mingw-install-over-msys.patch")
sha256sums=('0963fbe9ee90acd1d15e9f09e826eaaf8ea0312e854803caf2db0a6dd40f4464'
            '1099d01ea431ae38f2d9f3b836c337819dd2115b2d919d7b7998d013e82f076b')

prepare() {
  cd ${_realname}-${pkgver}
  patch -bp1 -i ${srcdir}/001-mingw-install-over-msys.patch
  cd -

  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
}

build() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -C lib CC=${MINGW_PREFIX}/bin/gcc
  make -C programs CC=${MINGW_PREFIX}/bin/gcc lz4 lz4c
}

check() {
  cd ${srcdir}
  msg2 "rm -f profile.lz4"
  rm -f profile.lz4 || true

  ${srcdir}/build-${MINGW_CHOST}/programs/lz4 /etc/profile profile.lz4
  ${srcdir}/build-${MINGW_CHOST}/programs/lz4 -d profile.lz4 profile
  diff -q /etc/profile profile

  rm profile
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make CC=${MINGW_PREFIX}/bin/gcc DESTDIR="${pkgdir}" PREFIX=${MINGW_PREFIX} install
}
